<?php defined('BASEPATH') OR exit('No direct script access allowed');

class diagnosis extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		if (!$this->ion_auth->logged_in())
		{
			//redirect them to the login page
			redirect('auth/login', 'refresh');
		}
       	$this->load->model('eng_diagnosis_model');
         $this->load->library('datatables');				
	}

	function new_assigned()
	{
	$id=$this->session->userdata('user_id');
	$meta['page_title'] = 'New Assigned Diagnosis';
	$this->load->view('common/header',$meta);		
	$this->load->view('assigned_diagnosis');
	$this->load->view('common/footer');
	}
	
	function getall()
		{ 
	   $id=$this->session->userdata('user_id');
		$at=$this->eng_diagnosis_model->get_view($id);
		print_r($at);
		
		}
		function nonwarranty_getall()
		{ 
	   $id=$this->session->userdata('user_id');
		$at=$this->eng_diagnosis_model->nonwarranty_view($id);
		print_r($at);
		
		}
		function getcurrent()
		{ 
	   $id=$this->session->userdata('user_id');
		$at=$this->eng_diagnosis_model->get_current_view($id);
		print_r($at);
		
		}
		function nonwarranty_getcurrent()
		{ 
	   $id=$this->session->userdata('user_id');
		$at=$this->eng_diagnosis_model->nonwarranty_current_view($id);
		print_r($at);
		
		}
		
	function view_detail($id)
{
      $this->load->library('form_validation');
		 $meta['page_title'] = "Edit Customer";
		 $user = $this->eng_diagnosis_model->edit_case($id)->row();
		 $access=$this->eng_diagnosis_model->edit_access($id)->row();
		 $this->data['case'] = $user;
		
		  $this->data['services_id'] = array(
			'name'  => 'case',
			'id'    => 'case_id',
			'type'  => 'text',
			'class' => 'span4',
		
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('case_id', $user->service_id),
		);
		 $this->data['adapter_detail'] = array(
			'name'  => 'adapter',
			'id'    => 'adapter',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('adapter_detail', $access->ac_adapter_detail),
		);
		$this->data['driver_detail'] = array(
			'name'  => 'drivercd',
			'id'    => 'drivercd',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('driver_detail', $access->driver_cd_detail),
		);
		 $this->data['bag_detail'] = array(
			'name'  => 'bag',
			'id'    => 'bag',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('bag_detail', $access->bag_detail),
		);
		 $this->data['hdd_detail'] = array(
			'name'  => 'hdd',
			'id'    => 'hdd',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('hdd_detail', $access->hdd_detail),
		);
		 $this->data['powercord_detail'] = array(
			'name'  => 'powerCord',
			'id'    => 'power_cordt',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('powercord_detail', $access->power_cord_detail),
		);
		 $this->data['carrycase_detail'] = array(
			'name'  => 'carryCace',
			'id'    => 'carry_case',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('carrycase_detail', $access->carry_casebelt_detail),
		);
		 $this->data['optical_detail'] = array(
			'name'  => 'opticalDrive',
			'id'    => 'optical_drivet',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('optical_detail', $access->optical_drive_detail),
		);
		 $this->data['modem_detail'] = array(
			'name'  => 'faxModem',
			'id'    => 'fax_modem',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('modem_detail', $access->modem_card_detail),
		);
		 $this->data['network_detail'] = array(
			'name'  => 'networkCard',
			'id'    => 'network_cardt',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('network_detail', $access->network_card_detail),
		);
		 $this->data['memory_detail'] = array(
			'name'  => 'memory',
			'id'    => 'memory',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('memory_detail', $access->memory_detail),
		);
		 $this->data['capacity_detail'] = array(
			'name'  => 'capacity',
			'id'    => 'capacity',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('capacity_detail', $access->capacity_detail),
		);
		 $this->data['tray_detail'] = array(
			'name'  => 'tray',
			'id'    => 'tray',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('tray_detail', $access->tray_detail),
		);
		 $this->data['battery_detail'] = array(
			'name'  => 'battery',
			'id'    => 'battery',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('battery_detail', $access->battry_serial),
		);
		 $this->data['cradle_detail'] = array(
			'name'  => 'cradle',
			'id'    => 'cradle',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('cradle_detail', $access->cradle_detail),
		);
		 $this->data['fdd_detail'] = array(
			'name'  => 'fdd',
			'id'    => 'fdd',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('fdd_detail', $access->fdd_detail),
		);
		 $this->data['itb_detail'] = array(
			'name'  => 'itb',
			'id'    => 'itb',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('itb_detail', $access->itb_detail),
		);
		 $this->data['wireless_detail'] = array(
			'name'  => 'wireless',
			'id'    => 'wireless',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('wireless_detail', $access->wireless_detail),
		);
		
		
		
		$this->data['service_date'] = array(
			'name'  => 'date',
			'id'    => 'date',
			'type'  => 'text',
			'class' =>'span7',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('case_date', $user->service_date),
		);
		$this->data['customer_company'] = array(
			'name'  => 'customer_company',
			'id'    => 'customer_company',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('customer_company', $user->company_name),
		);
		$this->data['customer_name'] = array(
			'name'  => 'customer_name',
			'id'    => 'customer_name',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('customer_name', $user->customer_name),
		);
		$this->data['customer_address'] = array(
			'name'  => 'customer_address',
			'id'    => 'customer_address',
			'rows' =>'5',
			'type'  => 'textarea',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('customer_address', $user->customer_address),
		);
		$this->data['customer_pincode'] = array(
			'name'  => 'customer_pincode',
			'id'    => 'customer_pincode',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('customer_pincode', $user->pincode),
		);
		$this->data['customer_landline'] = array(
			'name'  => 'customer_landline',
			'id'    => 'customer_landline',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('customer_landline', $user->landline),
		);$this->data['customer_mobile'] = array(
			'name'  => 'customer_mobile',
			'id'    => 'customer_mobile',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('customer_mobile', $user->mobile),
		);
		$this->data['customer_email'] = array(
			'name'  => 'customer_email',
			'id'    => 'customer_email',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('customer_email', $user->email),
		);
		$this->data['model_no'] = array(
			'name'  => 'model_no',
			'id'    => 'model_no',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('model_no', $user->model_no),
		);
		$this->data['product_no'] = array(
			'name'  => 'product_no',
			'id'    => 'product_no',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('product_no', $user->product_no),
		);
		$this->data['serial_no'] = array(
			'name'  => 'serial_no',
			'id'    => 'serial_no',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('serial_no', $user->serial_no),
		);
		$this->data['customer_password'] = array(
			'name'  => 'customer_password',
			'id'    => 'customer_password',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('customer_password', $user->password),
		);
		$this->data['customer_os'] = array(
			'name'  => 'customer_os',
			'id'    => 'customer_os',
			'type'  => 'text',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('customer_os', $user->operating_system),
		);
	
		$this->data['country_purch'] =$user->country_purchase;
		$this->data['service_id']=$user->service_id;	
		$this->data['id']=$id;
		$this->data['country_purchase'] = array(
			'name'  => 'country_purchase',
			'id'    => 'country_purchase',
			'type'  => 'select',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('country_purchase', $user->country_purchase),
		);
		
		$this->data['issue_reported'] = array(
			'name'  => 'issue_reported',
			'id'    => 'issue_reported',
			'type'  => 'textarea',
			'rows' =>'5',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('issue_reported', $user->issue_reported),
		);
		$this->data['enginer_diagnosis'] = array(
			'name'  => 'enginer_diagnosis',
			'id'    => 'enginer_diagnosis',
			'rows' =>'5',
			'type'  => 'textarea',
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('enginer_diagnosis', $user->engineer_diagnosis),
		);
		$this->data['ac_adapter'] = array(
			'name'  => 'ac_adapter',
			'id'    => 'ac_adapter',
			'checked' =>$access->ac_adapter,
			'readonly'  =>true,
            'value'=>$this->form_validation->set_value('ac_adapter', 1),
		);
		$this->data['driver_cd'] = array(
			'name'  => 'driver_cd',
			'id'    => 'driver_cd',
			'checked' => $access->driver_cd,
			'readonly'  =>true,
			'value'=>$this->form_validation->set_value('driver_cd', 1),
		);
		$this->data['bag'] = array(
			'name'  => 'cus_bag',
			'id'    => 'cus_bag',
			'checked' => $access->bag,
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('cus_bag', 1),
			
		);
			$this->data['hdd'] = array(
			'name'  => 'cus_hdd',
			'id'    => 'cus_hdd',
			'checked' =>$access->hdd,
			'readonly'  =>true,
			'value' => $this->form_validation->set_value('cus_hdd', 1),
		);
			$this->data['power_cord'] = array(
			'name'  => 'power_cord',
			'id'    => 'power_cord',
			'readonly'  =>true,
			'checked' =>$access->power_cord,
			'value' => $this->form_validation->set_value('power_cord',1),
		);
			$this->data['carrycase'] = array(
			'name'  => 'cus_carrycase',
			'id'    => 'cus_carrycase',
			'readonly'  =>true,
			'checked' =>$access->carry_casebelt,
			'value' => $this->form_validation->set_value('cus_carrycase', 1),
		);
			$this->data['optical_drive'] = array(
			'name'  => 'optical_drive',
			'id'    => 'optical_drive',
			'readonly'  =>true,
			'checked' =>$access->optical_drive,
			'value' => $this->form_validation->set_value('optical_drive', 1),
		);
			$this->data['modem_card'] = array(
			'name'  => 'modem_card',
			'id'    => 'modem_card',
			'readonly'  =>true,
			'checked' => $access->modem_card,
			'value' =>$this->form_validation->set_value('modem_card', 1),
		);
			$this->data['network_card'] = array(
			'name'  => 'network_card',
			'id'    => 'network_card',
			'readonly'  =>true,
			'checked' =>$access->network_card,
			'value' => $this->form_validation->set_value('network_card', 1),
		);
			$this->data['memory'] = array(
			'name'  => 'cus_memory',
			'id'    => 'cus_memory',
			'readonly'  =>true,
			'checked' =>$access->memory,
			'value' => $this->form_validation->set_value('cus_memory', 1),
		);
			$this->data['capacity'] = array(
			'name'  => 'cus_capacity',
			'id'    => 'cus_capacity',
			'readonly'  =>true,
			'checked' =>$access->capacity,
			'value' => $this->form_validation->set_value('cus_capacity', 1),
		);
			$this->data['tray'] = array(
			'name'  => 'cus_tray',
			'id'    => 'cus_tray',
			'readonly'  =>true,
			'checked' =>$access->tray,
			'value' => $this->form_validation->set_value('cus_tray', 1),
		);
			$this->data['battery_no'] = array(
			'name'  => 'battery_no',
			'id'    => 'battery_no',
			'readonly'  =>true,
			'checked' =>$access->battry,
			'value' => $this->form_validation->set_value('battery_no', 1),
		);
			$this->data['cradle'] = array(
			'name'  => 'cus_cradle',
			'id'    => 'cus_cradle',
			'readonly'  =>true,
			'checked' =>$access->cradle,
			'value' => $this->form_validation->set_value('cus_cradle', 1),
		);
			$this->data['fdd'] = array(
			'name'  => 'cus_fdd',
			'id'    => 'cus_fdd',
			'readonly'  =>true,
			'checked' =>$access->fdd,
			'value' => $this->form_validation->set_value('cus_fdd', 1),
		);
			$this->data['itb'] = array(
			'name'  => 'cus_itb',
			'id'    => 'cus_itb',
			'readonly'  =>true,
			'checked' =>$access->itb,
			'value' => $this->form_validation->set_value('cus_itb', 1),
		);
			$this->data['wireless_lan'] = array(
			'name'  => 'wireless_lan',
			'id'    => 'wireless_lan',
			'readonly'  =>true,
			'checked' =>$access->wireless,
			'value' => $this->form_validation->set_value('wireless_lan', 1),
		);
	/*	$this->data['comment_scratches'] = array(
			'name'  => 'scratches',
			'id'    => 'scratches',
			'rows' =>'5',
			'type'  => 'textarea',
			'value' => $this->form_validation->set_value('comment_scratches', $user->comment_scratches),
		);
		$this->data['comment_damages'] = array(
			'name'  => 'damages',
			'id'    => 'damages',
			'rows' =>'5',
			'type'  => 'textarea',
			'value' => $this->form_validation->set_value('comment_damages', $user->comment_damages),
		);
		$this->data['comment_other'] = array(
			'name'  => 'other',
			'id'    => 'other',
			'type'  => 'textarea',
			'rows' =>'5',
			'value' => $this->form_validation->set_value('comment_other', $user->comment_other),
		);*/
		$this->data['submit'] = array(
			'name' => 'submit',
			'id'   => 'submit',
			'type' => 'submit',
			'value' =>'Accept',
			'class' =>'btn btn-success'
		);
		 //$dat['country']=$this->case_model->get_country();
		
	
		
$meta['page_title'] = 'Detail of New diagnosis';
$this->load->view('common/header',$meta);		
$this->load->view('detail_diagnosis',$this->data);
$this->load->view('common/footer');

}	
		
public function accept($id)
{
$service_id=$this->eng_diagnosis_model->chk_serviceid($id)->row();
if(!empty($service_id))
{
$case=array('status_id'=>2);
$this->eng_diagnosis_model->update_nonwarranty_case($case,$id);
$insert=array('status_id'=>2,);
$this->eng_diagnosis_model->update_nonwarranty_diagnosis($id,$insert);
}
else{
$newcase='CASE/'.$id;
$case=array('status_id'=>2);
$this->eng_diagnosis_model->update_case($case,$id);
$insert=array('status_id'=>2,);
$this->eng_diagnosis_model->update_diagnosis($id,$insert);
}

redirect('/engineer/diagnosis/ongoing_process');

}	
  public function ongoing_process()
  {
  $meta['page_title'] = 'Current Diagnosis';
	$this->load->view('common/header',$meta);		
	$this->load->view('current_diagnosis');
	$this->load->view('common/footer');
  
  
  
  
  }

public function dispatch_detail($id)
{
$case=$this->eng_diagnosis_model->get_case($id)->row();
$this->data['case']=$case;
//$this->data['case_id']=$id;
$meta['page_title'] = 'Current Diagnosis dispatch ';
$this->load->view('common/header',$meta);		
$this->load->view('diagnosis_dispatch',$this->data);
$this->load->view('common/footer');
  }
public function nonwarranty_dispatch_detail($id)
{
$case=$this->eng_diagnosis_model->get_nonwarrantycase($id)->row();
$this->data['case']=$case;
$meta['page_title'] = 'Current Diagnosis dispatch ';
$this->load->view('common/header',$meta);		
$this->load->view('nonwarranty/diagnosis_dispatch',$this->data);
$this->load->view('common/footer');
  }
public function dispatch_slo()
{
                
				$sl_no = $this->input->post('sl_no');
				$hp_case=$this->input->post('hp_case');
				$case_id=$_REQUEST['case_id'];
				$diagnosis_id=$this->eng_diagnosis_model->get_diagnosis($case_id)->row();
				$case_no=$_REQUEST['case_no'];
			    $part_name=$this->input->post('part_name');
				$part_code=$this->input->post('part_code');
				$so_no=$this->input->post('slo_no');
			    $length = count($sl_no);
				
					for($i=0; $i<$length; $i++){
						
						$data['case_id']=$case_id;
						$data['name']=$part_name[$i];
				       $data['code']=$part_code[$i];
				      $data['so_no'] =$so_no[$i];
				$this->eng_diagnosis_model->dispatch_diagnosis($data);
						}
               						
                $this->eng_diagnosis_model->update_status($diagnosis_id->id);
				$this->eng_diagnosis_model->update_case1($case_id,$hp_case);
                   redirect('/engineer/diagnosis/dispatch_view','refresh');

}
public function dispatch_part()
{
	           $sl_no = $this->input->post('sl_no');
				$case_id=$_REQUEST['case_id'];
				$diagnosis_id=$this->eng_diagnosis_model->nonwarranty_diagnosis($case_id)->row();
				$case_no=$_REQUEST['case_no'];
			    $part_name=$this->input->post('part_name');
				$part_code=$this->input->post('part_code');
				$so_no=$this->input->post('model_no');
			    $length = count($sl_no);
				
					for($i=0; $i<$length; $i++){
						
						$data['case_id']=$case_id;
						$data['name']=$part_name[$i];
				       $data['code']=$part_code[$i];
				      $data['model'] =$so_no[$i];
					
				$this->eng_diagnosis_model->dispatch_nonwarranty_diagnosis($data);
						}
               				
                $this->eng_diagnosis_model->update_nonwarranty_status($diagnosis_id->id);
				$this->eng_diagnosis_model->update_nonwarranty_case1($case_id);
                   redirect('/engineer/diagnosis/dispatch_view','refresh');
}
public function dispatch_view()
{
 $meta['page_title'] = 'Dispatched Diagnosis';
	$this->load->view('common/header',$meta);		
	$this->load->view('dispatch_diagnosis');
	$this->load->view('common/footer');



}

public function getdispatch()
{
  $id=$this->session->userdata('user_id');
		$at=$this->eng_diagnosis_model->get_dispatch_view($id);
		print_r($at); 
}
public function nonwarranty_getdispatch()
{
  $id=$this->session->userdata('user_id');
		$at=$this->eng_diagnosis_model->nonwarranty_dispatch_view($id);
		print_r($at); 
}

public function dispatch_detail_view($id)
{
$case=$this->eng_diagnosis_model->get_case_no($id)->row();
$this->data['case']=$case;
$this->data['case_id']=$id;
$this->data['so']=$this->eng_diagnosis_model->get_slo($id);
$meta['page_title'] = 'Detail Of Dispatch';
	$this->load->view('common/header',$meta);		
	$this->load->view('dispatch_detail',$this->data);
	$this->load->view('common/footer');

}
public function dispatch_detail_nonwarranty($id)
{	
$case=$this->eng_diagnosis_model->get_case_nonwarranty($id)->row();
$this->data['case']=$case;
$this->data['case_id']=$id;
$this->data['so']=$this->eng_diagnosis_model->get_part($id);
$meta['page_title'] = 'Detail Of Completed Diagnosis';
$this->load->view('common/header',$meta);		
$this->load->view('nonwarranty/diagnosis_completed_detail',$this->data);
$this->load->view('common/footer');



		
}	
}
